//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_CL_EVENT_H
#define _UX_CL_EVENT_H

#include "CLDevice.h"

namespace Engine
{
namespace CLSystems
{

	//
	// CL Event Callback
	//

	class ICLEventCallback
	{
	public:
		virtual void operator () (CLEvent *pEvent, cl_event_status::type eStatus) = 0;
	};


	//
	// CL Event
	//

	class _EXPORT_ CLEvent : public CLBaseObject
	{
	protected:
		cl_event			_pEvent;
		ICLEventCallback *	_pCallback;
		
	protected:
		virtual void _RetainRef()	const;
		virtual void _ReleaseRef()	const;
		virtual uint _GetRefCount()	const;
		virtual void _Destroy();

		static void CALLBACK _s_Callback(cl_event pEvent, cl_int iStatus, void *pUserData);

	public:
		CLEvent();
		CLEvent(cl_event pEvent);
		~CLEvent();

		bool  Create(ICLEventCallback *pCallback = nullptr);
		void  Destroy();
		
		bool  Wait() const;
		void  SetCallback(ICLEventCallback *pCallback);
		bool  GetCommandType(cl_event_command::type &eType) const;
		bool  GetStatus(cl_event_status::type &eType) const;
		bool  SetStatus(cl_event_status::type eType = cl_event_status::COMPLETE);
		bool  GetProfilingTime(cl_event_time::type eType, uint64 &uTime) const;

		cl_event	GetIdent()	 const	{ return _pEvent; }

		static bool s_Wait(const cl_event_array_t &aEvents);
	};

//-------------------------------------------------------------------

}	// CLSystems
}	// Engine

#endif	// _UX_CL_EVENT_H